<?php
class M_DbTable_Hotel extends Apps_Db_Table_Abstract {
	protected $_name = 'hotel';

	const STATUS_ACTIVE  	= 1;
	const STATUS_INACTIVE  	= 0;
	const STATUS_DELETED  	= -1;

	const BEST_SELLING_TRUE 	= 1;
	const BEST_SELLING_FALSE 	= 0;

	const SPECIAL_OFFER_TRUE 	= 1;
	const SPECIAL_OFFER_FALSE 	= 0;

	public function getList() {
		$q = $this->_db
				  ->select()
				  ->from(array('h'   => $this->_name), null)
				  ->join(array('h_t' => 'hotel_type'), 'h_t.id = h.hotel_type_id', null)
				  ->join(array('a' 	 => 'article'), 'a.reference_id = h.id', null)
				  ->where('a.reference_type =?', M_DbTable_Article::REFERENCE_TYPE_HOTEL)
				  ->where('h.status !=?', self::STATUS_DELETED)
				  ->order('h.name ASC')
				  ->columns(
				  		array('id'					=>  'h.id',
							  'name'				=>	'h.name',
							  'en_name'				=>	'h.en_name',
							  'phone'				=>	'h.phone',
							  'email'				=>	'h.email',
							  'address'				=>	'h.address',
							  'en_address'			=>	'h.en_address',
							  'best_selling'		=>	'h.best_selling',
							  'special_offer'		=>	'h.special_offer',
							  'status'		        =>	'h.status',
							  'meta_keyword'		=>	'h.meta_keyword',
							  'meta_description'	=>	'h.meta_description',
							  'header_title'		=>	'h.header_title',
							  'title'				=>	'a.title',
							  'hotel_type_en_title'	=>	'h_t.en_title'
				  ));
		return $q;
	}

	public function getHotel($id) {
		$q = $this->_db
				  ->select()
				  ->from(array('h'   => $this->_name))
				  ->join(array('h_t' => 'hotel_type'), 'h_t.id = h.hotel_type_id', null)
				  ->join(array('r'   => 'region'), 'r.id = h.region_id', null)
				  ->join(array('c'   => 'country'), 'c.id = r.country_id', null)
				  ->join(array('a' 	 => 'article'), 'a.reference_id = h.id', null)
				  ->where('a.reference_type =?', M_DbTable_Article::REFERENCE_TYPE_HOTEL)
				  ->where('h.id =?', $id)
				  ->columns(
				  		array(//'id'						=>  'h.id',
// 							  'name'					=>	'h.name',
// 							  'en_name'					=>	'h.en_name',
// 							  'phone'					=>	'h.phone',
// 							  'hotline'					=>	'h.hotline',
// 							  'fax'						=>	'h.fax',
// 							  'email'					=>	'h.email',
// 							  'address'					=>	'h.address',
// 							  'en_address'				=>	'h.en_address',
// 							  'description'				=>	'h.description',
// 				  		      'best_selling'		    =>	'h.best_selling',
// 				  		      'special_offer'		    =>	'h.special_offer',
// 							  'meta_keyword'			=>	'h.meta_keyword',
// 							  'meta_description'		=>	'h.meta_description',
// 							  'header_title'			=>	'h.header_title',

							  'country_id'				=>	'c.id',
							  'region_id'				=>	'r.id',

							  'hotel_type_title'		=>	'h_t.title',

							  'title'					=>	'a.title',
							  'en_title'				=>	'a.en_title',
				  			  'overview'				=>	'a.overview',
				  			  'en_overview'				=>	'a.en_overview',
				  			  'detail'					=>	'a.detail',
				  			  'en_detail'				=>	'a.en_detail'
				  ));
		return $q;
	}
}